﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using QuocTeViet.DO;
using QuocTeViet.BL;

namespace QuocTeViet.Module
{
    public partial class ucBreadcrumb : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;
            url = url.Substring(1, url.Length - 1);
            string url1 = url.Replace(".", "/");
            string Module = url1.Substring(0, url1.IndexOf("/"));
          
                lbHome.Text = "Trang chủ ";
                if (Module == "danh-muc-xe")
                {
                    if (Request.QueryString["IDNH"] != null)
                    {
                        int NhanHieuID = int.Parse(Request.QueryString["IDNH"]);
                        string NhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/danh-muc-xe.aspx'> Sản phẩm</a>" + " » ";
                        lblTitle.Text += "<a href='/danh-muc-xe/hang-xe/" + NhanHieuID + "/" + FriendlyUrl(NhanHieu) + "'" + ">" + NhanHieu + "</a>";
                    }
                    else if (Request.QueryString["LoaiSP"] != null)
                    {
                        int LoaiSP = int.Parse(Request.QueryString["LoaiSP"]);
                        string title = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSP }).TenLoaiSanPham;
                        lblTitle.Text = "<a href='/Products.aspx'> Sản phẩm</a>" + " » " + "<a href='/Products/LoaiSP/" + LoaiSP + "/" + FriendlyUrl(title) + "'" + ">" + title + "</a>";
                    }
                    else if (Request.QueryString["Filter"] != null)
                    {
                        int LoaiSPID = int.Parse(Session["LoaiSP"].ToString());
                        int NhanHieuID = int.Parse(Request.QueryString["Filter"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/Products.aspx'> Sản phẩm</a>" + " » " + "<a href='/Products/Filter/" + NhanHieuID + "/" + FriendlyUrl(titleNhanHieu) + "'" + ">" + titleLoaiSP + " - " + titleNhanHieu + "</a>";


                    }
                    else if (Request.QueryString["FilterDM"] != null)
                    {
                        int LoaiSPID = int.Parse(Request.QueryString["FilterDM"]);
                        int NhanHieuID = int.Parse(Session["NhanHieu"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/Products.aspx'> Sản phẩm</a>" + " » " + "<a href='/Products/FilterDM/" + LoaiSPID + "/" + FriendlyUrl(titleLoaiSP) + "'" + ">" + titleNhanHieu + " - " + titleLoaiSP + "</a>";
                    }

                    else
                    {
                        lblTitle.Text = "<a href='/danh-muc-xe.aspx'> Sản phẩm</a>";
                    }
                }
                else if (Module == "tim-kiem")
                {
                    lblTitle.Text = "<a href='/tim-kiem/" + Request.QueryString["ID"].ToString() + "/default.aspx'> Tìm kiếm \"" + Request.QueryString["ID"].ToString() + "\"</a>";
                }
                else if (Module == "ve-chung-toi")
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        string title = new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = ID }).Title;

                        lblTitle.Text = "<a href='/ve-chung-toi/" + ID + "/" + FriendlyUrl(title) + "'>" + title + "</a>";
                    }
                }
                else if (Module == "noi-dung")
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        string title = new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = ID }).Title;

                        lblTitle.Text = "<a href='/noi-dung/" + ID + "/" + FriendlyUrl(title) + "'>" + title + "</a>";
                    }
                }

                else if (Module == "Category")
                {
                    if (Request.QueryString["ID"] != null)
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        if (ID == 7)
                        {
                            lblTitle.Text = "<a href='/Category/3/Tin-Tuc.aspx'>Tin tức</a>";
                        }
                    }
                }
                else if (Module == "bai-viet")
                {
                    lblTitle.Text = "<a href='/noi-dung/4/tin-tuc.aspx'> Tin tức</a>";
                }
                else if (Module == "tu-khoa")
                    lblTitle.Text = "<a href='/tu-khoa.aspx'> Tags</a>";
                else if (Module == "lien-he")
                    lblTitle.Text = "<a href='/lien-he.aspx'> Liên hệ</a>";
                else if (Module == "ThongTin")
                    lblTitle.Text = "<a href='/ThongTin/" + Session["IDDN"].ToString() + "/Thong-tin-ca-nhan.aspx'> Thông tin cá nhân</a>";
                else if (Module == "san-pham")
                {
                    cmsSanPhamDO obj = new cmsSanPhamBL().Select(new cmsSanPhamDO { SanPhamID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/Products.aspx'> Sản phẩm</a> » <a href='/Product/" + Request.QueryString["ID"].ToString() + "/" + FriendlyUrl(obj.TenSanPham) + "'>" + obj.TenSanPham + "</a>";
                }
                else if (Module == "Album")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>» <a href='/" + url + "'> Album - " + obj.Title + "</a>";
                }
                else if (Module == "AlbumCover")
                {
                    try
                    {
                        string url2 = Request.Url.AbsolutePath;
                        cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                        lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                    }
                    catch
                    {
                        lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                    }
                }
                else if (Module == "AlbumImage")
                {
                    string url2 = Request.Url.AbsolutePath;
                    try
                    {
                        cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>» <a href='/" + url + "'> Album - " + obj.Title + "</a>";
                    }
                    catch
                    {
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>";
                    }
                }
                else if (Module == "Image")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>» <a href='/" + url + "'>Album - " + obj.Title + "</a>";
                }
                else if (Module == "AlbumDetai")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsImagesDO obj = new cmsImagesBL().Select(new cmsImagesDO { ImageID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>» <a href='/Album/" + obj.AlbumID + "/Album.aspx'>Album - " + new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = obj.AlbumID }).Title + "</a> » <a href='/" + url + "'>AlbumDetail - " + obj.Title + "</a>";
                }
                else
                {
                    lblTitle.Text = "<a href='/" + Module + ".aspx'>" + Module + " </a>";
                }
 
        }

        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}